// EDVector3d.cpp: implementation of the EDVector3d class.
//
//////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "EDVector3d.h"
#include "EDPoint3d.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

const EDVector3d EDVector3d::kIdentity;

EDVector3d::EDVector3d()
{
}

EDVector3d::~EDVector3d()
{
}

EDVector3d::EDVector3d (
	const EDSQLExpression& exp0,
	const EDSQLExpression& exp1,
	const EDSQLExpression& exp2 )
	: x ( exp0 ), y ( exp1 ), z ( exp2 )
{
}

EDVector3d::EDVector3d (
	const CString& str0,
	const CString& str1,
	const CString& str2 )
	: x ( str0 ), y ( str1 ), z ( str2 )
{
}

EDVector3d& EDVector3d::operator = ( const EDVector3d& v )
{
	x = v.x;
	y = v.y;
	z = v.z;
	return *this;
}

EDVector3d& EDVector3d::operator = ( const AcGeVector3d& v )
{
	x.m_strExpression.Format ( _T ( "%f" ), v.x );
	y.m_strExpression.Format ( _T ( "%f" ), v.y );
	z.m_strExpression.Format ( _T ( "%f" ), v.z );
	return *this;
}

BOOL EDVector3d::operator == ( const EDVector3d& v ) CONST
{
	return x == v.x && y == v.y && z == v.z;
}

void EDVector3d::Replace ( const CVarArray* pVarAr, const int nStart )
{
	EDSQLExpression::Replace ( &x, pVarAr, nStart );
	EDSQLExpression::Replace ( &y, pVarAr, nStart );
	EDSQLExpression::Replace ( &z, pVarAr, nStart );
}

BOOL EDVector3d::IsSingleDigital()
{
	if ( !EDSQLExpression::IsSingleDigitalVar ( &x ) )
		return FALSE;
	if ( !EDSQLExpression::IsSingleDigitalVar ( &y ) )
		return FALSE;
	if ( !EDSQLExpression::IsSingleDigitalVar ( &z ) )
		return FALSE;

	return TRUE;
}

void EDVector3d::Set (
	const EDSQLExpression& exp0,
	const EDSQLExpression& exp1,
	const EDSQLExpression& exp2 )
{
	x = exp0;
	y = exp1;
	z = exp2;
}

void EDVector3d::Set (
	const CString& str0,
	const CString& str1,
	const CString& str2 )
{
	x.m_strExpression = str0;
	y.m_strExpression = str1;
	z.m_strExpression = str2;
}

BOOL EDVector3d::SetBy( INT& iLastPos, CONST CString& strSource, INT iStartPos, INT iEndPos )
{
	EDPoint3d pt;
	if ( pt.SetBy( iLastPos, strSource, iStartPos, iEndPos ) )
	{
		x = pt.x;
		y = pt.y;
		z = pt.z;
		return TRUE;
	}

	return FALSE;
}

VOID EDVector3d::Enlist( String2String& aStr2Exp )
{
	aStr2Exp.SetAt( _T( "__V_X__" ), (CString)x );
	aStr2Exp.SetAt( _T( "__V_Y__" ), (CString)y );
	aStr2Exp.SetAt( _T( "__V_Z__" ), (CString)z );
}

BOOL EDVector3d::Delist( CONST String2Double& aStr2Dbl, AcGeVector3d& aV )
{
	if ( aStr2Dbl.GetCount() != 3 )
		return FALSE;

	AcGeVector3d v;
	if ( aStr2Dbl.Lookup( _T( "__V_X__" ), v.x ) == FALSE )
		return FALSE;

	if ( aStr2Dbl.Lookup( _T( "__V_Y__" ), v.y ) == FALSE )
		return FALSE;

	if ( aStr2Dbl.Lookup( _T( "__V_Z__" ), v.z ) == FALSE )
		return FALSE;

	aV = v;
	return TRUE;
}
